/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.CompanyInfo;
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.GroupManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import java.sql.SQLException;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class AddGroup extends AbstractAction
/*    */ {
/* 32 */   private static Logger logger = Logger.getLogger(AddGroup.class.getName());
/*    */ 
/*    */   public AddGroup(AbstractHttpServlet servlet) {
/* 35 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 41 */     User user = super.getLoginUser(request);
/*    */ 
/* 43 */     String groupName = Util.getURLParameter(request
/* 44 */       .getParameter("groupName"));
/*    */ 
/* 46 */     int parentGroupId = Util.getURLIntParameter(request
/* 47 */       .getParameter("parentGroupId"));
/*    */ 
/* 49 */     GroupManager manager = new GroupManager();
/*    */ 
/* 51 */     int id = manager.add(groupName, parentGroupId, user.companyId, 
/* 52 */       user.userId);
/*    */ 
/* 54 */     if (id <= 0) {
/* 55 */       super.showErrorMessage(response, "部门添加失败，请稍后重试");
/* 56 */       return;
/*    */     }
/*    */ 
/*    */     try
/*    */     {
/* 61 */       CompanyInfo company = super.getCompany(user.companyId);
/* 62 */       company.setGroups(manager.list(user.companyId));
/*    */     } catch (DBException e) {
/* 64 */       logger.warn("add group failed", e);
/*    */     } catch (SQLException e) {
/* 66 */       logger.warn("add group failed", e);
/*    */     }
/*    */ 
/* 69 */     response.setContentType("text/html;charset=utf-8");
/* 70 */     PrintWriter out = response.getWriter();
/*    */ 
/* 72 */     JSONObject jsonObject = new JSONObject();
/* 73 */     jsonObject.put("error", "0");
/* 74 */     jsonObject.put("groupId", Integer.valueOf(id));
/* 75 */     out.println(jsonObject);
/* 76 */     out.flush();
/* 77 */     out.close();
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.AddGroup
 * JD-Core Version:    0.6.1
 */